package com.jiyun;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;
import java.util.Set;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:applicationContext-redis.xml")
public class TestDemo {
    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void setValue(){
        redisTemplate.boundValueOps("name").set("zs");
    }
    @Test
    public void getValue(){
        Object name = redisTemplate.boundValueOps("name").get();
        System.out.println(name);
    }
    @Test
    public void deleteValue(){
        redisTemplate.delete("name");
    }

    @Test
    public void testSetValue1(){
        redisTemplate.boundListOps("namelist1").rightPush("张三");
        redisTemplate.boundListOps("namelist1").rightPush("王五");
        redisTemplate.boundListOps("namelist1").rightPush("王二");
    }

/**    
  * 显示右压栈集合    
  */

    public void testGetValue1(){
        List list = redisTemplate.boundListOps("namelist1").range(0, 1);
        System.out.println(list);
    }
    @Test
    public void testSearchByIndex(){
        String s = (String)redisTemplate.boundListOps("namelist1").index(1);
        System.out.println(s);
    }

    @Test
    public void testSetValue(){
        redisTemplate.boundHashOps("namehash").put("a", "赵丽");
        redisTemplate.boundHashOps("namehash").put("b", "赵六");
        redisTemplate.boundHashOps("namehash").put("c", "赵武");
        redisTemplate.boundHashOps("namehash").put("d", "张二");
    }

    @Test
    public void testGetKeys(){
        List s = redisTemplate.boundHashOps("namehash").values();
        System.out.println(s);
    }





}



